package com.conorroche.taskmanagement;

import android.content.Context;
import android.database.Cursor;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class TagsHelper {

	/**
	 * @param args
	 */
	TagsHelper(Context ctx, ListView l) {
		context = ctx;
		list = l;
	}
	TagsHelper(Context ctx){
		context = ctx;
	}
	public void getTagView(){
		
		db = new DBAdapter(context);
		db.open();
		Cursor allTags = db.getAllTags();
		if (allTags.getCount() > 0){
			tags = new String[allTags.getCount()];
			tagIds = new int[allTags.getCount()];
			int count = 0;
			allTags.moveToFirst();
			while(!allTags.isAfterLast()){
				tags[count] = allTags.getString(allTags.getColumnIndex("name"));
				tagIds[count] = allTags.getInt(allTags.getColumnIndex("_id") + 1);
				count++;
				allTags.moveToNext();
			}
		}
		db.close();
		//create a list view of all tasks
		adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, tags );
		list.setAdapter(adapter);
	}
	public ListView getList(){
		return list;
	}
	public void updateAdapter(String n){
		//adapter.add(n);
		adapter = null;
		getTagView();
	}
	public String[] getTags(){
		return tags;
	}
	public int[] getTagIds(){
		return tagIds;
	}

	private DBAdapter db;
	private ArrayAdapter<String> adapter;
	private  ListView list;
	private Context context;
	private String[] tags;
	private int[] tagIds;
}
